package cn.itcast.demo;

import cn.itcast.dao.cargo.FactoryDao;
import cn.itcast.domain.cargo.Factory;
import cn.itcast.domain.cargo.FactoryExample;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath*:spring/application-*.xml")
public class SpringJunit {

    @Autowired
    private FactoryDao factoryDao;

    @Test
    public void test1(){
        //selectByExample(FactoryExample example); --全查/条件查

        //全查
        FactoryExample factoryExample = new FactoryExample();
        List<Factory> list = factoryDao.selectByExample(factoryExample);
        for (Factory factory : list) {
            System.out.println(factory);
        }

    }


    @Test
    public void test2(){
        //selectByExample(FactoryExample example); --全查/条件查

        //全查
        FactoryExample factoryExample = new FactoryExample();
        FactoryExample.Criteria criteria = factoryExample.createCriteria();
        //设置条件 and
        criteria.andFactoryNameLike("%天%");
        criteria.andContactsEqualTo("渠海");

        List<Factory> list = factoryDao.selectByExample(factoryExample);
        for (Factory factory : list) {
            System.out.println(factory);
        }

    }
}
